/*
    $Header: /Windows/Shell/ShellExt.root/ShellExt/src/CShellExtXML.h 1     08-01-05 0:08 Ken $
    $Log: /Windows/Shell/ShellExt.root/ShellExt/src/CShellExtXML.h $
 * 
 * 1     08-01-05 0:08 Ken
*/


#pragma once

#import <msxml3.dll>
//#import <msxml6.dll> raw_interfaces_only

#include <string>
#include <list>

using namespace std;
using namespace MSXML2;

class IDoXMLCb
{
public:
//
// called when shellext.xml file is parsed and executed
// pvHnd: each command context handle
// return true, if callback deal the juction info correctly and then this info will be delete
    virtual BOOL VOnXMLCmd(VOID* Hnd)=0;
    virtual const TCHAR* VGetCatalog()=0;
};

typedef IDoXMLCb* (*pfnCreateDoXMLCbIns)();

class CShellExtXML
{
public:
    CShellExtXML();
    ~CShellExtXML();
    BOOL Init(const TCHAR* pszPath, BOOL fForeceCreate);

//
// get and set command paras
    // this function can only be called within pfnOnXMLCmd
    static BOOL GetCmdInfo(VOID* Hnd, const TCHAR* pszName, _variant_t& vtValue );

    VOID* BgnSetCmdInfo(const TCHAR* pszCmdCat);
    BOOL SetCmdInfo(VOID* Hnd, const TCHAR* pszPara, _variant_t& vtValue);
    VOID EndSetCmdInfo(VOID* Hnd);

public:
    VOID DoShellExtXML();

private:
    MSXML2::IXMLDOMNodePtr  GetChildNodeForece(MSXML2::IXMLDOMNodePtr & ptrNodeParent, const TCHAR*  pszChld);
    VOID AddWhiteSpaceToNode(MSXML2::IXMLDOMNodePtr & ptrNode, bool fNewLine, int nTabs);


private:
    IXMLDOMDocument2Ptr m_ptrDoc;
    MSXML2::IXMLDOMNodePtr  m_ptrNodeRoot;

    TCHAR m_szShellExtXMLFile[MAX_PATH];

private:
    IDoXMLCb** m_pIDoXMLCbS;

//
// static members
private:
    static pfnCreateDoXMLCbIns s_pfnCreateDoXMLCbIns[];
    static int s_IDoXMLCbNumb;

// XML create init string
    static const TCHAR s_szXMLInitStr[];
};

class CDoXMLCbCMD: public IDoXMLCb
{
public:
    BOOL VOnXMLCmd(VOID* Hnd);
    const TCHAR* VGetCatalog(){return _T("CMD");};

public:
    static IDoXMLCb* CreateDoXMLCbCMDIns(){return new CDoXMLCbCMD;};
};


class CDoXMLCbJunct: public IDoXMLCb
{
public:
    BOOL VOnXMLCmd(VOID* Hnd);
    const TCHAR* VGetCatalog(){return _T("Junction");};

public:
    static IDoXMLCb* CreateDoXMLCbJunctIns(){return new CDoXMLCbJunct;};
};


